package com.ouc.openplatform.ouc.authManage.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ouc.openplatform.ouc.authManage.dao.NJ_RoleInfoDAO;
import com.ouc.openplatform.ouc.authManage.model.NJ_RoleInfo;
import com.ouc.openplatform.ouc.authManage.service.NJ_RoleInfoService;
import com.ouc.openplatform.pojo.EUDataGridResult;

public class NJ_RoleInfoServiceImpl implements NJ_RoleInfoService {
	private NJ_RoleInfoDAO nj_roleInfoDao;

	public NJ_RoleInfoDAO getNj_roleInfoDao() {
		return nj_roleInfoDao;
	}

	public void setNj_roleInfoDao(NJ_RoleInfoDAO nj_roleInfoDao) {
		this.nj_roleInfoDao = nj_roleInfoDao;
	}

	@Override
	public int saveRoleInfo(NJ_RoleInfo roleinfo) {
		return nj_roleInfoDao.insert(roleinfo);
	}

	@Override
	public int deleteRoleInfo(int id) {
		return nj_roleInfoDao.deleteByPrimaryKey(id);
	}

	@Override
	public int updateRoleInfo(NJ_RoleInfo roleinfo) {
		return nj_roleInfoDao.updateByPrimaryKeySelective(roleinfo);
	}

	@Override
	public EUDataGridResult getRoleInfo(NJ_RoleInfo roleinfo, int page, int rows) {
		// 分页处理
		PageHelper.startPage(page, rows);
		List<NJ_RoleInfo> select = nj_roleInfoDao.select(roleinfo);
		// 创建一个返回值对象
		EUDataGridResult result = new EUDataGridResult();
		result.setRows(select);
		// 取记录总条数
		PageInfo<NJ_RoleInfo> pageInfo = new PageInfo<NJ_RoleInfo>(select);
		result.setTotal(pageInfo.getTotal());
		return result;
	}

	// 5.获取角色信息总条数-----sxl
	@Override
	public int getAllCount() {
		int flag = nj_roleInfoDao.selectCount(null);
		return flag;
	}

	// 6.判断角色名是否存在-----sxl
	@Override
	public int IsRoleName(String rolename) {
		NJ_RoleInfo roleInfo = nj_roleInfoDao.getRoleName(rolename);
		return roleInfo == null ? 0 : 1;
	}

	// 7.查询所有角色权限信息-----sxl
	@Override
	public List<NJ_RoleInfo> getAllRoleInfo(NJ_RoleInfo roleInfo) {
		return nj_roleInfoDao.select(roleInfo);
	}
}
